package controller;

import business.datacenter.*;
import business.other.*;
import business.other.punish.*;
import datacenter.domain.*;
import datacenter.mapper.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import other.domain.*;
import other.mapper.*;
import sun.util.calendar.BaseCalendar;
import sybase.domain.*;
import util.AllUtil;
import util.StringUtil;

import javax.annotation.Resource;
import java.sql.Ref;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by SunZZ on 2016/6/15.
 */
@Controller
//@Service
public class OtherController {

    @Resource(name = "allUtil")
    AllUtil allUtil;
    //===========================表彰信息==============================//
    @Resource(name = "recognitionService")
    private HZCreditRecognitionService hzCreditRecognitionService;

    @Resource(name = "newsAgencyService")
    private NewsAgencyService newsAgencyService;

    @Resource(name = "statisticalOfficeService")
    private StatisticalOfficeService statisticalOfficeService;

    @Resource(name = "technologyCommitteeService")
    private TechnologyCommitteeService technologyCommitteeService;

    @Resource(name = "tourismCommitteeService")
    private TourismCommitteeService tourismCommitteeService;

    //========================生产事故=================================//
    @Resource(name = "accidentService")
    private HZCreditAccidentService hzCreditAccidentService;

    @Resource(name = "fireAccidentsService")
    private FireSafetyAccidentService fireSafetyAccidentService;

    @Resource(name = "productionAccidentsService")
    private ProductionSafetyAccidentsService productionSafetyAccidentsService;



    //============================法院信息=============================//
    @Resource(name = "creditCourtInfoService")
    private HZCreditCourtInfoService hzCreditCourtInfoService;

    @Resource(name = "courtInfoService")
    private CourtInfoService courtInfoService;

    @Resource(name = "debtsBilkingService")
    private EnterpriseDebtsBilkingService enterpriseDebtsBilkingService;


    //===========================行政处罚==============================//

    @Resource(name = "creditPunishinfoService")
    private HZCreditPunishinfoService hzCreditPunishinfoService;

    @Resource(name = "antiaircraftPunishService")
    private AntiaircraftPunishInfoService antiaircraftPunishInfoService;

    @Resource(name = "aquaticPunishService")
    private AquaticPunishInfoService aquaticPunishInfoService;

    @Resource(name = "cityMPunishService")
    private CityMPunishInfoService cityMPunishInfoService;

    @Resource(name = "constructionPunishSerrvice")
    private ConstructionPunishInfoSerrvice constructionPunishInfoSerrvice;

    @Resource(name = "environmentPunishService")
    private EnvironmentPunishInfoService environmentPunishInfoService;

    @Resource(name = "firePunishService")
    private FirePunishInfoService firePunishInfoService;

    @Resource(name = "hResourcesPunishService")
    private HResourcesPunishInfoService hResourcesPunishInfoService;

    @Resource(name = "landPunishService")
    private LandPunishInfoService landPunishInfoService;

    @Resource(name = "newPunishService")
    private NewPunishInfoService newPunishInfoService;

    @Resource(name = "peoplePunishService")
    private PeoplePunishInfoService peoplePunishInfoService;

    @Resource(name = "qualityPunishService")
    private QualityPunishInfoService qualityPunishInfoService;

    @Resource(name = "reformPunishService")
    private ReformPunishInfoService reformPunishInfoService;

    @Resource(name = "securityPunishService")
    private SecurityPunishInfoService securityPunishInfoService;

    @Resource(name = "tourPunishService")
    private TourPunishInfoService tourPunishInfoService;

    //===========================表彰信息==============================//
    @RequestMapping(value = "Recontest.htm")
    public String saveRecongnition()
    {
//        List<NewsAgency> origin = newsAgencyService.selectNewsAgency();
//        List<StatisticalOffice> originStatis= statisticalOfficeService.selectStatisticalOffice()
        List<HZCreditRecognition> data = new ArrayList<>();

        List<NewsAgency> newsAgencyList =  newsAgencyService.selectNewsAgency();
        List<StatisticalOffice> statisticalOfficeList = statisticalOfficeService.selectStatisticalOffice();
        List<TechnologyCommittee> technologyCommitteeList = technologyCommitteeService.selectTechnologyCommittee();
        List<TourismCommittee> tourismCommitteeList = tourismCommitteeService.selectTourismCommittee();
        for (NewsAgency newsdata:newsAgencyList) {
//            info =null;
            HZCreditRecognition info = new HZCreditRecognition();
            info.setCompanyname(newsdata.getF10());
            info.setRecognitioncode(newsdata.getF11());
            if(newsdata.getF04()!=null)
            info.setRecognitiondate(newsdata.getF04());
            info.setRecognitiondept(newsdata.getF08());
            info.setRecognitionname(newsdata.getF05());
            info.setRecognitioninfo(newsdata.getF05());
            data.add(info);
        }
        for(StatisticalOffice statistdata:statisticalOfficeList){
//            info =null;
            HZCreditRecognition info = new HZCreditRecognition();
            info.setRecognitiondept("市统计局");
            info.setRecognitionname(statistdata.getF02());
            info.setRecognitioncode(statistdata.getF03());
            info.setRecognitioninfo(statistdata.getF02());
            if(statistdata.getF06()!=null)
            info.setRecognitiondate(statistdata.getF06());
            info.setCompanyname(statistdata.getF04());
            data.add(info);
        }
        for ( TechnologyCommittee technologydata:technologyCommitteeList){
//            info =null;
            HZCreditRecognition info = new HZCreditRecognition();
            info.setRecognitiondept(technologydata.getF09());
            info.setRecognitionname(technologydata.getF07());
            info.setRecognitioncode(technologydata.getF08());
            info.setRecognitioninfo(technologydata.getF11());
            if(technologydata.getF10()!=null)
            info.setRecognitiondate(StringUtil.strToDate(technologydata.getF10(),"yyyy.MM"));
            info.setCompanyname(technologydata.getF04());
            data.add(info);
        }
        for (TourismCommittee tourismdata:tourismCommitteeList){
//            info =null;
            HZCreditRecognition info = new HZCreditRecognition();
            info.setRecognitiondept(tourismdata.getF06());
            info.setRecognitionname(tourismdata.getF05());
            info.setRecognitioncode(tourismdata.getF03());
            info.setRecognitioninfo(tourismdata.getF05());
            if(tourismdata.getF07()!=null)
            info.setRecognitiondate(tourismdata.getF07());
            info.setCompanyname(tourismdata.getF02());
            data.add(info);

        }
        hzCreditRecognitionService.saveHZCreditRecognition(data);
        System.out.print("reco");
        return "test";
    }


    //============================法院信息=============================//
    @RequestMapping(value = "CourtInfo.htm")
    public String saveCourtInfo()
    {
        List<HZCreditCourtInfo> data = new ArrayList<>();

//        for (CourtInfo courtInfo:courtInfoService.getCourtInfo()){
//            HZCreditCourtInfo info = new HZCreditCourtInfo();
//            info.setCaseno(courtInfo.getCaseno());
//            info.setRunreasoncode(courtInfo.getRunreasoncode());
//            info.setRunorgname(courtInfo.getRunorgname());
//            info.setRunreason(courtInfo.getRunreason2());
//            info.setCasedate(StringUtil.strToDate(courtInfo.getCasedate(),"yyyyMMdd"));
//            info.setClosecasedate(StringUtil.strToDate(courtInfo.getClosecasedate(),"yyyyMMdd"));
//            info.setRuntarget(courtInfo.getRuntarget());
//            info.setRuntargetamount(courtInfo.getRuntargetamount());
//            info.setRunedtarget(courtInfo.getRunedtarget());
//            info.setRunedtargetamount(courtInfo.getRunedtargetamount());
//            info.setClosecasemode(courtInfo.getClosecasemode());
//            info.setCasestat(courtInfo.getCasestat());
//            info.setRunvaliddate(StringUtil.strToDate(courtInfo.getRunvaliddate(),"yyyyMMdd"));
//            info.setCompanyname(courtInfo.getOrgname());
//            info.setCompanycode(courtInfo.getOrgacode());
//            data.add(info);
//        }
//        System.out.print("sybase court"+data.size());
        for(EnterpriseDebtsBilking enterpriseDebtsBilking:enterpriseDebtsBilkingService.getEnterpriseDebtsBilking()){
            HZCreditCourtInfo info = new HZCreditCourtInfo();
            info.setCaseno(enterpriseDebtsBilking.getF04());
//            info.setRunreasoncode("");
//            info.setRunorgname("");
            info.setRunreason(enterpriseDebtsBilking.getF09());
//            info.setRuntarget("");
//            info.setRuntargetamount("");
//            info.setRunedtarget("");
//            info.setRunedtargetamount("");
//            info.setClosecasemode("");
            info.setCasestat(enterpriseDebtsBilking.getF10());
            info.setCompanyname(enterpriseDebtsBilking.getF02());
//            if (null!=enterpriseDebtsBilking.getF03()&&enterpriseDebtsBilking.getF03().length()<20) {
                info.setCompanycode(enterpriseDebtsBilking.getF03());
//            }
            data.add(info);
        }
        hzCreditCourtInfoService.saveHZCreditCourtInfo(data);
        System.out.print("court"+data.size());
        return "test";
    }


    //========================生产事故=================================//
    @RequestMapping(value = "Accident.htm")
    public String saveAccident() {
        List<HZCreditAccident> data = new ArrayList<>();

        for (FireSafetyAccident fireSafetyAccident:fireSafetyAccidentService.getFireSafetyAccident()){
            HZCreditAccident info = new HZCreditAccident();
            info.setAccidentdate(fireSafetyAccident.getF08());
            info.setAccidentspot(fireSafetyAccident.getF06());
            if (fireSafetyAccident.getF10()!=null)
            info.setDeathtoll(fireSafetyAccident.getF10().intValue());
            if (fireSafetyAccident.getF11()!=null)
            info.setInjured(fireSafetyAccident.getF11().intValue());
            info.setAccidenttype("消防火灾事故信息");
            info.setAccidentreason(fireSafetyAccident.getF09());
            info.setCompanyname(fireSafetyAccident.getF06());
            data.add(info);
        }
        for (ProductionSafetyAccidents productionSafetyAccidents:productionSafetyAccidentsService.getProductionSafetyAccidents()){
            HZCreditAccident info = new HZCreditAccident();
            info.setAccidentdate(productionSafetyAccidents.getF03());
            info.setAccidentspot(productionSafetyAccidents.getF05());
            if (productionSafetyAccidents.getF06()!=null)
                info.setDeathtoll(productionSafetyAccidents.getF06().intValue());
            if (productionSafetyAccidents.getF07()!=null)
                info.setInjured(productionSafetyAccidents.getF07().intValue());
            info.setAccidenttype(productionSafetyAccidents.getF08());
            info.setAccidentreason(productionSafetyAccidents.getF09());
            info.setCompanyname(productionSafetyAccidents.getF04());
            data.add(info);
        }
        hzCreditAccidentService.saveHZCreditAccident(data);
        System.out.print("Action");
        return "test";
    }


    //===========================行政处罚==============================//
    @RequestMapping(value = "Punish.htm")
    public String savePunish() {
        List<HZCreditPunishinfo> data =new ArrayList<>();
//        HZCreditPunishinfo info = new HZCreditPunishinfo();
        UUID uuid= UUID.randomUUID();
        String s = uuid.toString();
        for (AntiaircraftPunishInfo antiaircraftPunishInfo:antiaircraftPunishInfoService.getAntiaircraftPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("市人防办");
            info.setPunishreason(antiaircraftPunishInfo.getF05());
            info.setPunishresult(antiaircraftPunishInfo.getF07());
            info.setPunishdate(antiaircraftPunishInfo.getF08());
            info.setCompanyname(antiaircraftPunishInfo.getF03());
            data.add(info);
//            allUtil
            allUtil.writeObjectFile(info);
        }

        for(AquaticPunishInfo aquaticPunishInfo:aquaticPunishInfoService.getAquaticPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("市农业局");
            info.setPunishreason(aquaticPunishInfo.getF03());
            info.setPunishresult(aquaticPunishInfo.getF04());
            info.setPunishdate(aquaticPunishInfo.getF06());
            info.setCompanyname(aquaticPunishInfo.getF01());
            data.add(info);
        }
//        for(CityMPunishInfo cityMPunishInfo:cityMPunishInfoService.getCityMPunishInfo()){
//            HZCreditPunishinfo info = new HZCreditPunishinfo();
//            if (cityMPunishInfo.getF15()!=null) {
//                info.setPunishdept(cityMPunishInfo.getF15());
//            }else
//            {
//                info.setPunishdept("市城市管理局");
//            }
//            info.setPunishreason(cityMPunishInfo.getF02());
//            info.setPunishresult(cityMPunishInfo.getF09());
//            info.setPunishdate(cityMPunishInfo.getF10());
//            info.setCompanyname(cityMPunishInfo.getF05());
//            data.add(info);
//        }

        for(ConstructionPunishInfo constructionPunishInfo:constructionPunishInfoSerrvice.getConstructionPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (constructionPunishInfo.getF08()!=null)
                info.setPunishdept(constructionPunishInfo.getF08());
            else
                info.setPunishdept("市建委");

            info.setPunishreason(constructionPunishInfo.getF05());
            info.setPunishresult(constructionPunishInfo.getF07());
            info.setPunishdate(constructionPunishInfo.getF09());
            info.setCompanyname(constructionPunishInfo.getF04());
            data.add(info);
        }

        for(EnvironmentPunishInfo environmentPunishInfo:environmentPunishInfoService.getEnvironmentPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("市环保局");
            info.setPunishreason(environmentPunishInfo.getF04());
            info.setPunishresult(environmentPunishInfo.getF06());
            info.setPunishdate(environmentPunishInfo.getF07());
            info.setCompanyname(environmentPunishInfo.getF02());
            data.add(info);
        }
        for(FirePunishInfo firePunishInfo:firePunishInfoService.getFirePunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (firePunishInfo.getF10()!=null)
                info.setPunishdept(firePunishInfo.getF10());
            else
                info.setPunishdept("市公安消防局");

            info.setPunishreason(firePunishInfo.getF05());
            info.setPunishresult(firePunishInfo.getF08());
            info.setPunishdate(firePunishInfo.getF07());
            info.setCompanyname(firePunishInfo.getF03());
            data.add(info);
        }
        for(HResourcesPunishInfo hResourcesPunishInfo:hResourcesPunishInfoService.getHResourcesPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (hResourcesPunishInfo.getF05()!=null)
                info.setPunishdept(hResourcesPunishInfo.getF05());
            else
                info.setPunishdept("市人力社保局");
            info.setPunishreason(hResourcesPunishInfo.getF03());
//            info.setPunishresult();
//            info.setPunishdate();
            info.setCompanyname(hResourcesPunishInfo.getF02());
            data.add(info);
        }

        for(LandPunishInfo landPunishInfo:landPunishInfoService.getLandPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (landPunishInfo.getF08()!=null)
                info.setPunishdept(landPunishInfo.getF08());
            else
                info.setPunishdept("市国土资源局");
            info.setPunishreason(landPunishInfo.getF05());
            info.setPunishresult(landPunishInfo.getF07());
            info.setPunishdate(landPunishInfo.getF09());
            info.setCompanyname(landPunishInfo.getF04());
            data.add(info);
        }

        for(NewPunishInfo newPunishInfo:newPunishInfoService.getNewPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (newPunishInfo.getF12()!=null)
                info.setPunishdept(newPunishInfo.getF12());
            else
                info.setPunishdept("市文广新闻出版局");
            info.setPunishreason(newPunishInfo.getF04());
            info.setPunishresult(newPunishInfo.getF06());
            info.setPunishdate(newPunishInfo.getF07());
            info.setCompanyname(newPunishInfo.getF05());
            data.add(info);
        }
        for(PeoplePunishInfo peoplePunishInfo:peoplePunishInfoService.getPeoplePunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("民政局");
            info.setPunishreason(peoplePunishInfo.getF12());
            info.setPunishresult(peoplePunishInfo.getF10());
            info.setPunishdate(StringUtil.strToDate(peoplePunishInfo.getF09(),"yyyy-MM-dd"));
            info.setCompanyname(peoplePunishInfo.getF04());
            data.add(info);
        }
        for (QualityPunishInfo qualityPunishInfo:qualityPunishInfoService.getQualityPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            if (qualityPunishInfo.getF08()!=null)
                 info.setPunishdept(qualityPunishInfo.getF08());
            else
                info.setPunishdept("市质监局");
            info.setPunishreason(qualityPunishInfo.getF04());
            info.setPunishresult(qualityPunishInfo.getF06());
            info.setPunishdate(StringUtil.strToDate(qualityPunishInfo.getF07(),"dd/MM/yyyy"));
            info.setCompanyname(qualityPunishInfo.getF03());
            data.add(info);
        }
        for(ReformPunishInfo reformPunishInfo:reformPunishInfoService.getReformPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("省发改委");
            info.setPunishreason(reformPunishInfo.getF06());
            info.setPunishresult(reformPunishInfo.getF07());
            info.setPunishdate(StringUtil.strToDate(reformPunishInfo.getF01(),"yyyyMMdd"));
            info.setCompanyname(reformPunishInfo.getF05());
            data.add(info);
        }
        for(SecurityPunishInfo securityPunishInfo:securityPunishInfoService.getSecurityPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("市安全监管局");
            info.setPunishreason(securityPunishInfo.getF04());
            info.setPunishresult(securityPunishInfo.getF07());
            info.setPunishdate(StringUtil.strToDate(securityPunishInfo.getF09(),"yyyy年"));
            info.setCompanyname(securityPunishInfo.getF03());
            data.add(info);
        }
        for(TourPunishInfo tourPunishInfo:tourPunishInfoService.getTourPunishInfo()){
            HZCreditPunishinfo info = new HZCreditPunishinfo();
            info.setPunishdept("市旅委");
            info.setPunishreason(tourPunishInfo.getF06());
            info.setPunishresult(tourPunishInfo.getF08());
            info.setPunishdate(tourPunishInfo.getF09());
            info.setCompanyname(tourPunishInfo.getF04());
            data.add(info);
        }
//        hzCreditPunishinfoService.saveHZCreditPunishinfo(data);
        System.out.print("Punish");
        return "test";
    }

}
